#coding=utf8

class T:
    ERROR = -2 #<error>
    EOF = -1 #<token - end of stream>
    NONE = 0 #<not token>
    WHITESPACE = 1 #<whitespace>
    PUBLIC = 2 #public
    STATIC = 3 #static
    VOID = 4 #void
    MAIN = 5 #main
    LEFT_BRACKET = 6 #(
    RIGHT_BRACKET = 7 #)
    STRING = 8 #String
    LEFT_QUAD_BRACKET = 9 #[
    RIGHT_QUAD_BRACKET = 10 #]
    IDENTIFIER = 11 #<identifier>
    LEFT_FIGURE_BRACKET = 12 #{
    RIGHT_FIGURE_BRACKET = 13 #}
    CLASS = 14 #class
    EXTENDS = 15 #extends
    #TYPE = 16
    BOOLEAN = 17 #boolean
    IF = 18 #if
    ELSE = 19 #else
    RETURN = 20 #return
    WHILE = 21 #while
    PRINT = 22 #System.out.println
    SEMICOLON = 23 #;
    EQUAL = 24 #=
    AND = 25 #&&
    LESS = 26 #<
    ADD = 27 #+
    SUB = 28 #-
    MUL = 29 #:
    DOT = 30 #.
    LENGTH = 31 #length
    INTEGER_VALUE = 32 #<integer value>
    TRUE = 33 #true
    FALSE = 34 #false
    THIS = 35 #this
    NEW = 36 #new
    EXCLAMATION = 37 #!
    COMMA = 38 #.
    INT = 39 #.

class Token(object):
    def __init__(self, type= T.NONE, value= None):
        self.type = type
        self.value = value

    def __int__(self):
        return self.Type()

    def __str__(self):
        result = "<" + self.TypeStr()
        if (self.type == T.IDENTIFIER or
            self.type == T.INTEGER_VALUE or
            self.type == T.ERROR):
            result += " value=" + str(self.value)
        result += ">"
        return result

    def Type(self):
        """
        Возвращает тип токена """
        return self.type

    def Value(self):
        """
        Возвращает значение токена (для IDENTIFIER, INTEGER_VALUE и ERROR) """
        return self.value

    def TypeStr(self):
        """
        Возвращает строковое представление типа токена """
        t = self.type

        if t == T.ERROR:
            return "ERROR"

        elif t == T.EOF:
            return "EOF"

        elif t == T.NONE:
            return "NONE"

        elif t == T.WHITESPACE:
            return "WHITESPACE"

        elif t == T.PUBLIC:
            return "public"

        elif t == T.STATIC:
            return "static"

        elif t == T.VOID:
            return "void"

        elif t == T.MAIN:
            return "main"

        elif t == T.LEFT_BRACKET:
            return "("

        elif t == T.RIGHT_BRACKET:
            return ")"

        elif t == T.STRING:
            return "String"

        elif t == T.LEFT_QUAD_BRACKET:
            return "["

        elif t == T.RIGHT_QUAD_BRACKET:
            return "]"

        elif t == T.IDENTIFIER:
            return "IDENTIFIER"

        elif t == T.LEFT_FIGURE_BRACKET:
            return "{"

        elif t == T.RIGHT_FIGURE_BRACKET:
            return "}"

        elif t == T.CLASS:
            return "class"

        elif t == T.EXTENDS:
            return "extends"

        elif t == T.BOOLEAN:
            return "boolean"

        elif t == T.IF:
            return "if"

        elif t == T.ELSE:
            return "else"

        elif t == T.RETURN:
            return "return"

        elif t == T.WHILE:
            return "while"

        elif t == T.PRINT:
            return "System.out.println"

        elif t == T.SEMICOLON:
            return ";"

        elif t == T.EQUAL:
            return "="

        elif t == T.AND:
            return "&&"

        elif t == T.LESS:
            return "<"

        elif t == T.ADD:
            return "+"

        elif t == T.SUB:
            return "-"

        elif t == T.MUL:
            return "*"

        elif t == T.DOT:
            return "."

        elif t == T.LENGTH:
            return "length"

        elif t == T.INTEGER_VALUE:
            return "INTEGER_VALUE"

        elif t == T.TRUE:
            return "true"

        elif t == T.FALSE:
            return "false"

        elif t == T.THIS:
            return "this"

        elif t == T.NEW:
            return "new"

        elif t == T.EXCLAMATION:
            return "!"

        elif t == T.COMMA:
            return ","

        elif t == T.INT:
            return "int"

        else:
            return "unknown"

